
var g_iApplicationID = -1;

function changeApplication()
{
	var e = document.getElementById("application");
	var option = e.options[e.selectedIndex];
	g_iApplicationID = Number(option.value);

	g_sTask = "";
	g_sTaskName = "";
	e = document.getElementById("task");
	e.length = 0;
	if(g_iApplicationID==-1)
	{
		e.options[e.length] = new Option("请先选择应用", -1);	
		hideContentList();
	}
	else
	{
		e.options[e.length] = new Option("请选择", -1);

		var sTask = g_oTask[g_iApplicationID];
		var aTask = sTask.split(";");
		
		var len = aTask.length;
		var arr = null;
		for(var i=0; i<len; i++)
		{
			arr = aTask[i].split(":");
			if(arr.length==2)
				e.options[e.length] = new Option(arr[1], arr[0]);
		}
	}
}

var g_sTask = "";
var g_sTaskName = "";
function changeTask()
{
	var e = document.getElementById("task");
	var option = e.options[e.selectedIndex];
	
	g_sTask = option.value;
	g_sTaskName = option.text;
	
	if(g_oApplication[g_iApplicationID].application=="content")
	{
		if(g_sTask=="detail")
		{
			loadContentList();
		}
		else if(g_sTask=="listing")
		{
			loadContentCategoryList();
		}
	}
	else
	{
		hideContentList();
	}
}





function hideContentList()
{
	$("#content-wrap").html("");
}

function loadContentList()
{
	$.ajax({
		type: "GET",
		url: "./?app=content&task=ajax_content_title_list",
		dataType: "json",
		success: function(json){
			if(json.status=="0")
			{
				var str = '<label class="item-title">请选择一篇文章: </label> <select id="content" onchange="javascript:changeContent();">';
				str += '<option value="0">请选择</option>';
				var aContent = json.content_list;
				for(var x in aContent)
				{
					str += '<option value="'+x+'">'+aContent[x]+'</option>';
				}
				str += '</select>';
				$("#content-wrap").html( str );
			}
		}
	});
}


function changeContent()
{
	var id = $("#content").val();
	if(id==0)
		$("#param").val("");
	else
		$("#param").val("id="+id);
}

function loadContentCategoryList()
{
	$.ajax({
		type: "GET",
		url: "./?app=content&task=ajax_content_category_name_list",
		dataType: "json",
		success: function(json){
			if(json.status=="0")
			{
				var str = '<label class="item-title">请选择一个分类: </label> <select id="content_category" onchange="javascript:changeContentCategory();">';
				str += '<option value="0">请选择</option>';
				var aCategory = json.category_list;
				var oCategory;
				for(var x in aCategory)
				{
					oCategory = aCategory[x];
					str += '<option value="'+oCategory.id+'">';
					if(oCategory.level>0)
					{
						for(var i=0; i<oCategory.level; i++) str += '&nbsp;&nbsp;&nbsp;';
						//str += '|_';
					}
					str += oCategory.name+'</option>';
				}
				str += '</select>';
				$("#content-wrap").html( str );
			}
		}
	});
}

function changeContentCategory()
{
	var id = $("#content_category").val();
	if(id==0)
		$("#param").val("");
	else
		$("#param").val("category_id="+id);
}

function save()
{
	if(g_iApplicationID==-1)
	{
		alert("请选择应用");
		return;
	}
	
	if(g_sTask=='')
	{
		alert("请选择任务");
		return;
	}
	
	var sLink = g_oApplication[g_iApplicationID].name+" > "+g_sTaskName;
	
	window.opener.saveLink(g_iMenuID, g_oApplication[g_iApplicationID].application , g_sTask, $("#param").val(), sLink);
	window.close();
}





